Imports System
Imports System.Configuration
Imports System.Web.Configuration

Partial Class Usercontrols_Admin_BlogSettings
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.Page.IsPostBack = False Then
            LoadSettings()
        End If

        Me.uxAdminPanel.Visible = ShowControls(SecurityMask.Admin, True)

    End Sub

#End Region

#Region " Save Data "

    Public Sub SaveSettings()
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then

            If IsNothing(AppSettingsSection.Settings("DisplayMostViewedBlogs")) Then
                AppSettingsSection.Settings.Add("DisplayMostViewedBlogs", Me.uxDisplayMostViewedBlogsCheckBox.Checked)
            Else
                AppSettingsSection.Settings("DisplayMostViewedBlogs").Value() = Me.uxDisplayMostViewedBlogsCheckBox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayMostCommentsBlogs")) Then
                AppSettingsSection.Settings.Add("DisplayMostCommentsBlogs", Me.uxDisplayMostCommentsBlogsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayMostCommentsBlogs").Value() = Me.uxDisplayMostCommentsBlogsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayHighestRankedBlogs")) Then
                AppSettingsSection.Settings.Add("DisplayHighestRankedBlogs", Me.uxDisplayHighestRankedBlogsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayHighestRankedBlogs").Value() = Me.uxDisplayHighestRankedBlogsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("EnableUserBlogs")) Then
                AppSettingsSection.Settings.Add("EnableUserBlogs", Me.uxEnableUserBlogsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("EnableUserBlogs").Value() = Me.uxEnableUserBlogsCheckbox.Checked
            End If

            configuration.Save()
        End If

    End Sub

    Public Sub SaveSettings(ByVal key As String, ByVal value As String)
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then
            AppSettingsSection.Settings(key).Value = value
            configuration.Save()
        End If
    End Sub

#End Region

#Region " Load Data "

    Public Sub LoadSettings()

        If Not (AppSettingsSection Is Nothing) Then
            If IsNothing(AppSettingsSection.Settings("DisplayMostViewedBlogs")) Then
                Me.uxDisplayMostViewedBlogsCheckBox.Checked = True
            Else
                Me.uxDisplayMostViewedBlogsCheckBox.Checked = AppSettingsSection.Settings("DisplayMostViewedBlogs").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayMostCommentsBlogs")) Then
                Me.uxDisplayMostCommentsBlogsCheckbox.Checked = True
            Else
                Me.uxDisplayMostCommentsBlogsCheckbox.Checked = AppSettingsSection.Settings("DisplayMostCommentsBlogs").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayHighestRankedBlogs")) Then
                Me.uxDisplayHighestRankedBlogsCheckbox.Checked = True
            Else
                Me.uxDisplayHighestRankedBlogsCheckbox.Checked = AppSettingsSection.Settings("DisplayHighestRankedBlogs").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("EnableUserBlogs")) Then
                Me.uxEnableUserBlogsCheckbox.Checked = False
            Else
                Me.uxEnableUserBlogsCheckbox.Checked = AppSettingsSection.Settings("EnableUserBlogs").Value()
            End If

        End If

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "



#End Region

End Class
